import java.util.Scanner;

/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-03-01
 * Time:21:30
 */
/**
 * 564. 寻找最近的回文数
 * 给定一个表示整数的字符串 n ，返回与它最近的回文整数（不包括自身）。如果不止一个，返回较小的那个。
 * “最近的”定义为两个整数差的绝对值最小。
 * 将前一半填入后一半：12321     n的一半的回文数
 * 将前一半加一填入后一半：12421     n的一半+1的回文数
 * 将前一半减一填入后一半：12221     n的一半-1的回文数
 * 下边界：9999       n的降一位最大回文数
 * 上边界：100001      n的升一位最小回文数
 * 这5个数之间，与n差的绝对值最小的数，就是答案*/
public class TestDemo {
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        System.out.println(nearestPalindromic1(s));

    }

    public static String nearestPalindromic1(String n) {
        long a = Long.parseLong(n);
        if (a > 0 && a < 10) {
            return (a - 1) + "";
        }
        if (a % 10 == 0) {
            long k = a;
            while (k % 10 == 0) {
                k /= 10;
            }
            if (k == 1) {
                return (a - 1) + "";
            }
        }
        if (a == 11) {
            return 9 + "";
        }
        if (a % 9 == 0) {
            long k = a;
            while (k % 10 == 9) {
                k /= 10;
            }
            if (k == 0) {
                return (a + 2) + "";
            }
        }
        long length = (long) Math.round(n.length() / 2.0);
        char[] chars = n.toCharArray();
        long ret = 0;
        for (int i = 0; i < length; i++) {
            ret *= 10;
            ret += (chars[i] - '0');
        }
        long ret1 = ret + 1;
        long ret2 = ret - 1;
        long ans = ret, ans1 = ret1, ans2 = ret2;
        if (n.length() % 2 != 0) {
            length = length - 1;
            long j = ret;
            while (j % 10 == 0) {
                j /= 10;
            }
            if (j == 1) {
                ret /= 10;
                ret1 /= 10;
            } else {
                ret /= 10;
                ret1 /= 10;
                ret2 /= 10;
            }
        }
        for (int i = 0; i < length; i++) {
            long a1 = ret % 10;
            long a2 = ret1 % 10;
            long a3 = ret2 % 10;
            ret /= 10;
            ret1 /= 10;
            ret2 /= 10;
            ans = (ans *= 10) + a1;
            ans1 = (ans1 *= 10) + a2;
            ans2 = (ans2 *= 10) + a3;
        }
        if (ans == a) {
            ans = Math.abs(ans1 - a) >= Math.abs(ans2 - a) ? ans2 : ans1;
            return ans + "";
        }
        long ans3 = Math.abs(ans1 - a) >= Math.abs(ans - a) ? ans : ans1;
        return (Math.abs(ans3 - a) >= Math.abs(ans2 - a) ? ans2 : ans3) + "";
    }


    //走方格的方案数
    public static int ans;

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int row = scanner.nextInt();
            int col = scanner.nextInt();
            findNum(0, 0, row, col);
            System.out.println(ans);
            ans = 0;
        }
    }

    //一旦向下/向右边走触碰到最下方的线或者最右边的线则认为该走法可行
    public static void findNum(int start, int end, int row, int col) {
        if (start == row || end == col) {
            ans++;
            return;
        }
        //向下走
        findNum(start + 1, end, row, col);
        //向右走
        findNum(start, end + 1, row, col);
    }

    //另类加法/不能用+ - 乘除
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println(addInt(a, b));
    }

    public static int addInt(int a, int b) {
        if (b == 0) {
            return a;
        }
        int c = a ^ b;
        int d = (a & b) << 1;
        return addInt(c, d);
    }


    //井字棋检测是否获胜
    public boolean checkWon(int[][] board) {
        for (int i = 0; i < board.length; i++) {
            if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] == 1) {
                return true;
            }
        }
        for (int i = 0; i < board[0].length; i++) {
            if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] == 1) {
                return true;
            }
        }
        if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] == 1) {
            return true;
        }
        if (board[1][1] == board[0][2] && board[1][1] == board[2][0] && board[1][1] == 1) {
            return true;
        }
        return false;
    }
    //牛客[编程题]密码强度等级
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            int sum = 0;
            if (s.length() <= 4) {
                sum += 5;
            } else if (s.length() <= 7) {
                sum += 10;
            } else {
                sum += 25;
            }
            int upperStr = 0;
            int lowerStr = 0;
            int digit = 0;
            int esymbol = 0;
            char[] chars = s.toCharArray();
            for (char c : chars) {
                if (Character.isUpperCase(c)) {
                    upperStr = 1;
                } else if (Character.isLowerCase(c)) {
                    lowerStr = 1;
                } else if (Character.isDigit(c)) {
                    digit++;
                } else {
                    esymbol++;
                }

            }
            if ((upperStr == 1 && lowerStr == 0) || (upperStr == 0 && lowerStr == 1)) {
                sum += 10;
            } else if (upperStr == 1 && lowerStr == 1) {
                sum += 20;
            }
            if (digit == 1) {
                sum += 10;
            } else if (digit > 1) {
                sum += 20;
            }

            if (esymbol == 1) {
                sum += 10;
            } else if (esymbol > 1) {
                sum += 25;
            }

            if (esymbol != 0 && upperStr != 0 && lowerStr != 0 && digit != 0) {
                sum += 5;
            } else if ((digit != 0 && esymbol != 0) && (upperStr != 0 || lowerStr != 0)) {
                sum += 3;
            } else if (digit != 0 && esymbol != 0) {
                sum += 2;
            }

            if (sum >= 90) {
                System.out.println("VERY_SECURE");
            } else if (sum >= 80) {
                System.out.println("SECURE");
            } else if (sum >= 70) {
                System.out.println("VERY_STRONG");
            } else if (sum >= 60) {
                System.out.println("STRONG");
            } else if (sum >= 50) {
                System.out.println("AVERAGE");
            }else if (sum>=25){
                System.out.println("WEAK");
            }else {
                System.out.println("VERY_WEAK");
            }
        }
    }
}
